home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Impresión / PrintThreePages / PrinterSelectionDialog.cs next >
Encoding:
Text File  |  2002-05-24  |  2.2 KB  |  70 lines

  1. //-----------------------------------------------------
  2. // PrinterSelectionDialog.cs ⌐ 2001 by Charles Petzold
  3. //-----------------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Drawing.Printing;
  7. using System.Windows.Forms;
  8.  
  9. class PrinterSelectionDialog: Form
  10. {
  11.      ComboBox combo;
  12.  
  13.      public PrinterSelectionDialog()
  14.      {
  15.           Text = "Seleccionar impresora";
  16.  
  17.           FormBorderStyle = FormBorderStyle.FixedDialog;
  18.           ControlBox      = false;
  19.           MaximizeBox     = false;
  20.           MinimizeBox     = false;
  21.           ShowInTaskbar   = false;
  22.           StartPosition   = FormStartPosition.Manual;
  23.           Location        = ActiveForm.Location +
  24.                                    SystemInformation.CaptionButtonSize +
  25.                                    SystemInformation.FrameBorderSize;
  26.  
  27.           Label label    = new Label();
  28.           label.Parent   = this;
  29.           label.Text     = "Impresora:";
  30.           label.Location = new Point(8, 8);
  31.           label.Size     = new Size(42, 8);
  32.  
  33.           combo = new ComboBox();
  34.           combo.Parent   = this;
  35.           combo.DropDownStyle = ComboBoxStyle.DropDownList;
  36.           combo.Location = new Point(64, 8);
  37.           combo.Size     = new Size(146, 8);
  38.  
  39.                // Agregar las impresoras instaladas al cuadro combinado.
  40.  
  41.           foreach (string str in PrinterSettings.InstalledPrinters)
  42.                combo.Items.Add(str);
  43.  
  44.           Button btn   = new Button();
  45.           btn.Parent   = this;
  46.           btn.Text     = "Aceptar";
  47.           btn.Location = new Point(40, 32);
  48.           btn.Size     = new Size(40, 16);
  49.           btn.DialogResult = DialogResult.OK;
  50.  
  51.           AcceptButton = btn;
  52.  
  53.           btn  = new Button();
  54.           btn.Parent = this;
  55.           btn.Text = "Cancelar";
  56.           btn.Location = new Point(120, 32);
  57.           btn.Size   = new Size(60, 16);
  58.           btn.DialogResult = DialogResult.Cancel;
  59.  
  60.           CancelButton = btn;
  61.  
  62.           ClientSize = new Size(220, 56);
  63.           AutoScaleBaseSize = new Size(4, 8);
  64.      }
  65.      public string PrinterName
  66.      {
  67.           set { combo.SelectedItem = value; }
  68.           get { return (string) combo.SelectedItem; }
  69.      }
  70. }